#' Online variance
#'
#' @param period rolling window period
#' @param type type of the rolling window
#'
#' @return a stateful function
#' @export
#'
new_variance <- function(period, type = c("ro", "ew", "cu", "vw", "cuvw"))
{
  type = match.arg(type)
  switch(type,
         ro = mk_online_func_x("variance", period),
         ew = mk_online_func_x("variance_ew", period),
         cu = mk_online_func_x("variance_cu"),
         vw = mk_online_func_xw("variance_vw", period),
         cuvw = mk_online_func_xw("variance_cuvw"))
}

#' Online annualised volatility
#'
#' @param period rolling window period
#' @param annualise number of days per annum
#' @param type type of the rolling window
#'
#' @return a stateful function
#' @export
#'
new_volatility <- function(period, annualise = 252L, type = c("ro", "ew", "cu"))
{
  type = match.arg(type)
  switch(type,
         ro = mk_online_func_x("volatility", period, annualise),
         ew = mk_online_func_x("volatility_ew", period, annualise),
         cu = mk_online_func_x("volatility_cu", annualise))
}
